package wt.hpad.model.local;

import android.content.ContentValues;

import org.litepal.crud.DataSupport;

import java.util.List;

import wt.hpad.model.bean.Dish;
import wt.hpad.model.bean.DishType;
import wt.hpad.model.bean.TableInfo;

/**
 * 处理本地数据
 * Created by wt on 12.20.
 */

public class DBHelper {

    public static int deleteAllTableInfo() {
        return DataSupport.deleteAll(TableInfo.class);
    }

    public static void updateAllTableInfo(List<TableInfo> datas) {
        DataSupport.saveAll(datas);
    }

    public static int updateTableInfo(TableInfo info) {
        ContentValues values = new ContentValues();
        values.put("status", info.status);
        return DataSupport.updateAll(TableInfo.class, values, "tableID=?", info.tableID);
    }

    public static List<TableInfo> queryAllTableInfo() {
        return DataSupport.findAll(TableInfo.class);
    }

    public static List<DishType> queryAllDishType() {
        return DataSupport.findAll(DishType.class);
    }

    public static List<Dish> queryDishForType(int dishTypeCode) {
        return DataSupport.select("dishID", "dishName", "dishTypeCode").where("dishTypeCode = ?", dishTypeCode + "").find(Dish.class);
    }

    public static List<Dish> queryAllDishs() {
        return DataSupport.findAll(Dish.class);
    }

    public static int deleteAllMenu() {
        return DataSupport.deleteAll(Dish.class);
    }

    public static void updateAllMenu(List<Dish> datas) {
        DataSupport.saveAll(datas);
    }

    public static int deleteAllType() {
        return DataSupport.deleteAll(DishType.class);
    }

    public static void updateAllType(List<DishType> datas) {
        DataSupport.saveAll(datas);
    }


}
